'''
Description: 
Author: HowsenFisher
Date: 2021-04-12 09:52:30
LastEditTime: 2021-04-12 11:19:04
LastEditors: liutq
Reference: 
'''
import socket
from Media.Voice.VoiceRecorder import VoiceRecorder
from threading import Thread
from multiprocessing import Process

class VoiceSender:
    def __init__(self,parent,ip,port):
        # Process.__init__(self)
        self.parent = parent
        # self.parent.newInfoSignal.emit("音频发送器初始化")
        self.ip = ip
        self.port = port
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.connect((self.ip,self.port))
        self.myVoiceRecorder = VoiceRecorder()
        self.send()
    
    def setAddr(self,ip,port):
        self.ip = ip
        self.port = port
    
    def send(self):
        
        while True:
            voiceData = b''
            try:
                voiceData = self.myVoiceRecorder.record()
            except Exception:
                break
            # print(len(voiceData))
            self.s.send(voiceData)

if __name__ == '__main__':
    myVoiceSender = VoiceSender("127.0.0.1",911)
    myVoiceSender.start()